package cn.changeforyou.web.cloud.auth.controller;

import cn.changeforyou.web.cloud.auth.dapator.ReactAdminPage;
import cn.changeforyou.web.cloud.auth.entity.User;
import cn.changeforyou.web.cloud.auth.entity.ftos.UserFTO;
import cn.changeforyou.web.cloud.auth.entity.vos.UserVO;
import cn.changeforyou.web.cloud.auth.service.UserService;
import cn.changeforyou.web.cloud.webBase.common.model.Result;
import cn.changeforyou.web.cloud.webBase.controller.AbstractController;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

@RestController
@RequestMapping("user")
public class UserController extends AbstractController {

    @Resource
    private UserService userService;

    @GetMapping("queryUsersByPage")
    public Result<ReactAdminPage<User>> queryUsersByPage() {
        return Result.success(new ReactAdminPage(userService.queryUsersByPage()));
    }

    @GetMapping("getUserById")
    public Result<UserVO> getUserById(Integer id) {
        validIsNull(id);
        return Result.success(userService.selectUserVO(id));
    }

    @GetMapping("getUserById2")
    public Result<User> getUserById2(Integer id) {
        validIsNull(id);
        return Result.success(userService.selectByIdWithResultTypeXml(id));
    }

    @PostMapping("addUser")
    public Result<User> addUser(@RequestBody @Valid UserFTO user) {
        return Result.success(userService.addEntity(user));
    }
}
